package com.example.treehole.ui.model

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Diversity1
import androidx.compose.material.icons.filled.Games
import androidx.compose.material.icons.filled.LocalDining
import androidx.compose.material.icons.filled.Science
import androidx.compose.material.icons.filled.SportsSoccer
import androidx.compose.material.icons.filled.TravelExplore
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

class SquareViewModel : ViewModel() {
    private val _selectedTag = MutableStateFlow(PostType.NO_TYPE)
    val selectedTag:StateFlow<PostType> = _selectedTag


    val tags = listOf(
        TagSection(PostType.NO_TYPE, "", null),
        TagSection(PostType.STUDY, "学习", Icons.Default.Science),
        TagSection(PostType.LOVE, "情感", Icons.Default.Diversity1),
        TagSection(PostType.ENTERTAINMENT, "玩乐", Icons.Default.LocalDining),
        TagSection(PostType.GAME, "游戏", Icons.Default.Games),
        TagSection(PostType.SPORT, "体育", Icons.Default.SportsSoccer),
        TagSection(PostType.SCIENCE, "科技", Icons.Default.TravelExplore)
    )

    fun updateTag(tag: PostType) {
        _selectedTag.value = tag
    }

    fun getTagNameByPostType():String{
        return tags.find { it.type == selectedTag.value }?.title ?:""
    }

    fun getTagNameByPostType(tag:PostType):String{
        return tags.find { it.type == tag }?.title ?:""
    }

    fun getTagByPostType(type: String):PostType{
        return tags.find { it.type.name == type }?.type ?:PostType.NO_TYPE
    }
}